/*
 * jiyan
 */
package com.jiyan.market.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.data.redis.core.RedisTemplate;
import springfox.documentation.annotations.ApiIgnore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Resource;
import com.rzhkj.core.tools.redis.RedisUtils;
import com.rzhkj.core.tools.StringTools;
import com.rzhkj.core.entity.BeanRet;
import com.rzhkj.core.entity.Page;
import com.jiyan.core.base.BaseCtrl;
import com.jiyan.market.facade.MarketRepairRecordSV;
import com.jiyan.market.entity.MarketRepairRecord;



/**
 * 维修记录
 *
 * @author jiyan
 */
@Controller
@RequestMapping("/marketRepairRecord")
@Api(value = "维修记录控制器", description = "维修记录控制器")
public class MarketRepairRecordCtrl extends BaseCtrl {
 private final static Logger logger = LoggerFactory.getLogger(MarketRepairRecordCtrl.class);

    @Resource
    protected RedisTemplate<String, Object> redisTemplate;
    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private MarketRepairRecordSV marketRepairRecordSV;



    /**
     * 查询维修记录详情信息
     *
     * @param id 
     * @return BeanRet
     */
    @ApiOperation(value = "查询维修记录详情信息", notes = "查询维修记录详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @GetMapping(value = "/loadById")
    @ResponseBody
    public BeanRet loadById(@PathVariable java.lang.Long id) {
        if(id == null){
          return BeanRet.create();
        }
        
        MarketRepairRecord marketRepairRecord = marketRepairRecordSV.load(id);
        logger.info(JSON.toJSONString(marketRepairRecord));
        return BeanRet.create(true, "查询详情信息", marketRepairRecord);
    }


    /**
     * 查询维修记录详情信息
     *
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询维修记录详情信息", notes = "查询维修记录详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/loadByCode")
    @ResponseBody
    public BeanRet loadByCode(@PathVariable java.lang.String code) {
        if(StringTools.isEmpty(code)){
          return BeanRet.create();
        }
        
        MarketRepairRecord marketRepairRecord = marketRepairRecordSV.loadByCode(code);
        logger.info(JSON.toJSONString(marketRepairRecord));
        return BeanRet.create(true, "查询详情信息", marketRepairRecord);
    }



    /**
     * 查询维修记录信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询维修记录信息集合", notes = "查询维修记录信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "deviceCode", value = "设备编码", paramType = "query"),
            @ApiImplicitParam(name = "sn", value = "sn 码 设备SN码", paramType = "query"),
            @ApiImplicitParam(name = "repairAccountCode", value = "账户编码", paramType = "query"),
            @ApiImplicitParam(name = "errorType", value = "错误类型", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态 更换配件修复replace_parts，需要返厂故障Return_factory，无法修复故障broken，一般故障修复general_fault", paramType = "query"),
            @ApiImplicitParam(name = "feedback", value = "反馈信息 256英文字符", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "维修时间", paramType = "query")
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore MarketRepairRecord marketRepairRecord,@ApiIgnore Page<MarketRepairRecord> page) {
        if (page == null) {
                return BeanRet.create(false, "分页对象不能为空");
        }
        page.setParams(JSON.parseObject(JSON.toJSONString(marketRepairRecord)));
        page = marketRepairRecordSV.getList(page);
        return BeanRet.create(true, "", page);
    }

    /**
     * 创建维修记录
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建维修记录", notes = "创建维修记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query", required = true),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query", required = true),
            @ApiImplicitParam(name = "deviceCode", value = "设备编码", paramType = "query", required = true),
            @ApiImplicitParam(name = "sn", value = "sn 码 设备SN码", paramType = "query", required = true),
            @ApiImplicitParam(name = "repairAccountCode", value = "账户编码", paramType = "query", required = true),
            @ApiImplicitParam(name = "errorType", value = "错误类型", paramType = "query", required = true),
            @ApiImplicitParam(name = "state", value = "状态 更换配件修复replace_parts，需要返厂故障Return_factory，无法修复故障broken，一般故障修复general_fault", paramType = "query", required = true),
            @ApiImplicitParam(name = "feedback", value = "反馈信息 256英文字符", paramType = "query", required = true),
            @ApiImplicitParam(name = "createTime", value = "维修时间", paramType = "query", required = true)
    })
    @PostMapping("/save")
    @ResponseBody
    public BeanRet save(@ApiIgnore MarketRepairRecord marketRepairRecord) {
        marketRepairRecordSV.save(marketRepairRecord);
        return BeanRet.create(true, "保存成功");
    }


    /**
     * 修改维修记录
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改维修记录", notes = "修改维修记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "deviceCode", value = "设备编码", paramType = "query"),
            @ApiImplicitParam(name = "sn", value = "sn 码 设备SN码", paramType = "query"),
            @ApiImplicitParam(name = "repairAccountCode", value = "账户编码", paramType = "query"),
            @ApiImplicitParam(name = "errorType", value = "错误类型", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态 更换配件修复replace_parts，需要返厂故障Return_factory，无法修复故障broken，一般故障修复general_fault", paramType = "query"),
            @ApiImplicitParam(name = "feedback", value = "反馈信息 256英文字符", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "维修时间", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore MarketRepairRecord marketRepairRecord) {
        marketRepairRecordSV.update(marketRepairRecord);
        return BeanRet.create(true, "修改成功");
    }

    /**
     * 删除维修记录
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除维修记录", notes = "删除维修记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query", required = true),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query", required = true)
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id,java.lang.String code) {
        if(id==null){
          return BeanRet.create(false,"不能为空");
        }
        if(code==null){
          return BeanRet.create(false,"编码不能为空");
        }
        marketRepairRecordSV.delete(id,code);
        return BeanRet.create(true, "删除MarketRepairRecord成功");
    }

}
